import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class ThreadDemo1 {
    public static void main(String[] args) {
        BlockingDeque<Integer> blockingDeque=new LinkedBlockingDeque<>();

        Thread product=new Thread(()->{
            int count=0;
            while(true) {
                try {
                    blockingDeque.put(count);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("生产元素：" + count);
                   count++;
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread constum=new Thread(()->{
            while(true) {
                try {
                 int rusult= blockingDeque.take();
                    System.out.println("消费元素："+rusult);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        product.start();
        constum.start();
    }
}
